Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial implementation #1

Merged
merged 14 commits into from
Feb 14, 2024
Merged

Initial implementation #1

merged 14 commits into from
Feb 14, 2024

Conversation

mistydemeo
Copy link
Contributor

This features the initial implementation of axoupdater. This version is mainly targeted for use as a standalone executable, but it has most of the work necessary for a library that can be embedded in into another program.

The updater executable is designed to be installed with a filename which indicates what it's meant to update; it then infers what program to update from its filename. For example, if it's installed as cargo-dist-update, it'll attempt to update cargo-dist. The update process looks like this:

  1. Determine what program to update based on the filename.
  2. Look up the current version of the program by looking for an install receipt installed in a standard path.
  3. Determine where newer versions are available based on the data in the install receipt.
  4. Contact that source to see what the latest non-rerelease is.
  5. If no update is needed, exit here.
  6. If an update is needed, download the installer and run it.

This version contains testing debug features; it tries to load install receipts from the current directory instead of the standard config path, and hardcodes the name of the program to update as "cargo-dist". These testing features are disabled in release builds.

Some work that isn't done yet:

  • The rest of the work for use as a library; this will need testing.
  • An audit of the dependency tree to see if this is too heavy for use as a dependency.
  • Axo Releases as a package source.
  • Windows support. (Partial Windows support is in this PR, but a few things are missing.)

@mistydemeo mistydemeo force-pushed the implementation branch 2 times, most recently from 7e4c7e0 to 5abb219 Compare January 18, 2024 19:51
@mistydemeo mistydemeo force-pushed the implementation branch 2 times, most recently from 4819fdb to b80bdce Compare January 23, 2024 01:12
Copy link
Contributor

@Gankra Gankra left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so far this looks reasonable

src/lib.rs Outdated Show resolved Hide resolved
Comment on lines +395 to +399
Utf8PathBuf::from(&path)
.file_name()
.map(|s| s.strip_suffix(".exe").unwrap_or(s))
.map(|s| s.strip_suffix("-update").unwrap_or(s))
.map(|s| s.to_owned())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting... this won't behave desirably for apps whose name doesn't match their primary binary's name, and which want to use this as a library.

For instance turso has a repo name "libsql" which ships an app named "libsql-server" whose only binary is "sqld", for legacy backcompat reasons.

https://github.com/tursodatabase/libsql/blob/main/libsql-server/Cargo.toml#L8
https://github.com/tursodatabase/libsql/releases

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For context, the "guess from filename" is intended for the standalone updater. That's why it's trying to strip -update from the end of the filename. End consumers of this as a library shouldn't use this method.

src/lib.rs Outdated
if cfg!(debug_assertions) {
Ok(Utf8PathBuf::try_from(current_dir()?)?)
} else {
let Some(home) = homedir::get_my_home()? else {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

btw this is the hardcore library for this stuff

https://crates.io/crates/dirs

it depends on a few os crates like redox_users and windows_sys, idk how much bloat that entails.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I started with dirs, but had to back out because I couldn't write the receipts using it. dirs only lets you access dir info for the platform it's running on; you can't, say, ask for what Windows dirs should look like when you're running on Linux. As a result, I could only really assemble actual receipt paths in bash/powershell, where I didn't have access to dirs. Here I'm matching exactly the logic I used there, rather than dirs's special logic that might not match it 1:1.

}

fn load_receipt_from_path(install_receipt_path: &Utf8PathBuf) -> AxoupdateResult<InstallReceipt> {
Ok(SourceFile::load_local(install_receipt_path)?.deserialize_json()?)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh nice, ok so we aren't being Super precious about deps (for now)


impl Release {
pub fn version(&self) -> String {
if let Some(stripped) = self.tag_name.strip_prefix('v') {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh geez can we get both of these into the manifest. we specifically send both to axoreleases because getting one from the other is a mess (your code will die on my-app-v1.0.0, my-app/v1.0.0, releases/1.0.0, ....

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(really cargo-dist should be told what the schema is for tags so the updater can construct them... sigh)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, it honestly would be a lot easier than going off the tag here.

Instead of branching behaviour based on debug assertions,
check for environment variables and use those instead.
@mistydemeo
Copy link
Contributor Author

Merging the impl for now; further changes will be smaller PRs from this.

@mistydemeo mistydemeo merged commit 2f9aacf into main Feb 14, 2024
7 checks passed
@mistydemeo mistydemeo deleted the implementation branch February 14, 2024 09:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants